package com.stephenone.jetpackdemo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelProviders;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.stephenone.jetpackdemo.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity {
    private MyViewModel myViewModel;
//    private TextView tvNumber;

    private ActivityMainBinding binding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_main);
//        tvNumber = findViewById(R.id.tv_number);

        binding = DataBindingUtil.setContentView(this,R.layout.activity_main);
//        myViewModel = ViewModelProviders.of(this).get(MyViewModel.class);
        myViewModel = new ViewModelProvider(this).get(MyViewModel.class);
//
//        myViewModel.getLikedNumber().observe(this, new Observer<Integer>() {
//            @Override
//            public void onChanged(Integer integer) {
//                binding.tvNumber.setText(String.valueOf(integer));
//            }
//        });

        binding.setData(myViewModel);
        binding.setLifecycleOwner(this);
    }

    public void onThumbUp(View view) {
        myViewModel.addLikedNumber(1);
    }

    public void onThumbDown(View view) {
        myViewModel.addLikedNumber(-1);
    }
}
